/**
 * Copyright (c) 2009 Teoti Graphix, LLC See:
 *     http://tkarchitecture.teotigraphix.org
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 * 
 * @author Michael Schmalle mschmalle@teotigraphix.com
 */
package org.teotigraphix.dx.patterns.component
{

import mx.core.IMXMLObject;

import org.teotigraphix.dx.interfaces.IBehaviorLayer;
import org.teotigraphix.dx.interfaces.IComponentBehaviorCore;
import org.teotigraphix.dx.interfaces.IComponentModelCore;
import org.teotigraphix.dx.interfaces.IComponentSkinCore;
import org.teotigraphix.dx.interfaces.IModelLayer;
import org.teotigraphix.dx.interfaces.ISkinLayer;
import org.teotigraphix.dx.interfaces.IToolKitComponent;
import org.teotigraphix.dx.interfaces.IToolKitFactory;
import org.teotigraphix.dx.patterns.behavior.ComponentBehaviorCore;
import org.teotigraphix.dx.patterns.layer.BehaviorLayer;
import org.teotigraphix.dx.patterns.layer.ModelLayer;
import org.teotigraphix.dx.patterns.layer.SkinLayer;
import org.teotigraphix.dx.patterns.model.ComponentModelCore;

/**
 * The default factory implementation for the toolkit.
 * 
 * <p>When the creation methods are called by the toolkit or another component,
 * the corrisponding property is checked first. If the property has been
 * defined in mxml, the property is considered set. The creation method
 * will use the set property and return it to the client.</p>
 * 
 * <p>If the corrisponding property has not been set declaritivly in mxml,
 * the factory will use it's default product that implements the correct interface
 * for the creation method.</p>
 * 
 * @copyright Teoti Graphix, LLC
 * @author Michael Schmalle
 * @date 07-08-09
 * 
 * @example
 * 
 * <p>Below is an example of the default <code>coreBehavior</code> 
 * implementation.</p>
 * 
 * <listing version="3.0">
 * public function createCoreBehavior():ICoreComponentBehavior
 * {
 *     return (_coreBehavior) ? _coreBehavior : new CoreComponentBehavior();
 * }
 * </listing>
 * 
 * @example
 * 
 * <p>The example below creates a new factory implementation in the 
 * Declarations block and binds it to the component's <code>toolKitFactory</code>
 * property.</p>
 * 
 * <listing version="3.0">
 * 
 * <fx:Declarations>
 *     <t:ToolKitFactory id="factory">
 *         <t:coreBehavior>
 *             <behaviors:MyEnhancedCoreBehavior/>
 *         </t:coreBehavior>
 *     </t:ToolKitFactory>
 * </fx:Declarations>
 * 
 * <components:Component toolKitFactory="{factory}"/>
 * 
 * </listing>
 * 
 * @example
 * 
 * <p>The example below creates a new factory implementation on the component
 * inline and assigns the new <code>coreBehavior</code></p>
 * 
 * <listing version="3.0">
 * 
 * <components:Component id="myComponent"/>
 *     <components:toolKitFactory>
 *         <t:ToolKitFactory>
 *             <t:coreBehavior>
 *                 <behaviors:MyEnhancedCoreBehavior/>
 *             </t:coreBehavior>
 *         </t:ToolKitFactory>
 *     <components:toolKitFactory>
 * </components:Component>
 * 
 * </listing>
 */
public class ToolKitFactory 
	   implements IMXMLObject, IToolKitFactory
{
	include "../../core/Version.as"
	
	//--------------------------------------------------------------------------
	//
	//  Properties :: Methods
	//
	//--------------------------------------------------------------------------
	
	//----------------------------------
	//  coreSkin
	//----------------------------------
	
	/**
	 * @private
	 */
	private var _coreSkin:IComponentSkinCore;

	/**
	 * Returns the mxml implementation of the <code>coreSkin</code>.
	 */
	public function get coreSkin():IComponentSkinCore
	{
		return _coreSkin;
	}
	
	/**
	 * @private
	 */
	public function set coreSkin(value:IComponentSkinCore):void
	{
		_coreSkin = value;
	}
	
	//----------------------------------
	//  coreBehavior
	//----------------------------------
	
	/**
	 * @private
	 */
	private var _coreBehavior:IComponentBehaviorCore;

	/**
	 * Returns the mxml implementation of the <code>coreBehavior</code>.
	 */
	public function get coreBehavior():IComponentBehaviorCore
	{
		return _coreBehavior;
	}
	
	/**
	 * @private
	 */
	public function set coreBehavior(value:IComponentBehaviorCore):void
	{
		_coreBehavior = value;
	}
	
	//----------------------------------
	//  coreModel
	//----------------------------------
	
	/**
	 * @private
	 */
	private var _coreModel:IComponentModelCore;

	/**
	 * Returns the mxml implementation of the <code>coreModel</code>.
	 */
	public function get coreModel():IComponentModelCore
	{
		return _coreModel;
	}
	
	/**
	 * @private
	 */
	public function set coreModel(value:IComponentModelCore):void
	{
		_coreModel = value;
	}
	
	//----------------------------------
	//  modelLayer
	//----------------------------------
	
	/**
	 * @private
	 */
	private var _modelLayer:IModelLayer;

	/**
	 * Returns the mxml implementation of the <code>modelLayer</code>.
	 */
	public function get modelLayer():IModelLayer
	{
		return _modelLayer;
	}
	
	/**
	 * @private
	 */
	public function set modelLayer(value:IModelLayer):void
	{
		_modelLayer = value;
	}
	
	//----------------------------------
	//  skinLayer
	//----------------------------------
	
	/**
	 * @private
	 */
	private var _skinLayer:ISkinLayer;

	/**
	 * Returns the mxml implementation of the <code>skinLayer</code>.
	 */
	public function get skinLayer():ISkinLayer
	{
		return _skinLayer;
	}
	
	/**
	 * @private
	 */
	public function set skinLayer(value:ISkinLayer):void
	{
		_skinLayer = value;
	}
	
	//----------------------------------
	//  behaviorLayer
	//----------------------------------
	
	/**
	 * @private
	 */
	private var _behaviorLayer:IBehaviorLayer;

	/**
	 * Returns the mxml implementation of the <code>behaviorLayer</code>.
	 */
	public function get behaviorLayer():IBehaviorLayer
	{
		return _behaviorLayer;
	}
	
	/**
	 * @private
	 */
	public function set behaviorLayer(value:IBehaviorLayer):void
	{
		_behaviorLayer = value;
	}
	
	//--------------------------------------------------------------------------
	//
	//  IMXMLObject API :: Methods
	//
	//--------------------------------------------------------------------------
	
	/**
	 * @private
	 */
	public function initialized(document:Object, id:String):void
	{
	}
	
	//--------------------------------------------------------------------------
	//
	//  IToolKitFactory API :: Methods
	//
	//--------------------------------------------------------------------------
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IToolKitFactory#createCoreSkin()
	 */
	public function createCoreSkin():IComponentSkinCore
	{
		return _coreSkin;
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IToolKitFactory#createCoreBehavior()
	 */
	public function createCoreBehavior():IComponentBehaviorCore
	{
		return (_coreBehavior) ? _coreBehavior : new ComponentBehaviorCore();
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IToolKitFactory#createCoreModel()
	 */
	public function createCoreModel():IComponentModelCore
	{
		return (_coreModel) ? _coreModel : new ComponentModelCore();
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IToolKitFactory#createModelLayer()
	 */
	public function createModelLayer():IModelLayer
	{
		return (_modelLayer) ? _modelLayer : new ModelLayer();
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IToolKitFactory#createSkinLayer()
	 */
	public function createSkinLayer():ISkinLayer
	{
		return (_skinLayer) ? _skinLayer : new SkinLayer();
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IToolKitFactory#createBehaviorLayer()
	 */
	public function createBehaviorLayer():IBehaviorLayer
	{
		return (_behaviorLayer) ? _behaviorLayer : new BehaviorLayer();
	}
	
	/**
	 * @copy org.teotigraphix.dx.interfaces.IToolKitFactory#createComponents()
	 */
	public function createComponents(client:IToolKitComponent):void
	{
	}
}
}